/*!
 * @file opp.c
 * @brief Object push profile related operation
 * @par Copyright (C) 2008 ALPS ELECTRIC CO., LTD
 */

#include "../alps_app/private.h"
/*!
 * @brief update OPP state.
 * 
 * @param state new OPP state.
 */
void oppUpdateState(oppState state)
{
	app.opp.opp_state = state;
}

/*!
 * @brief Object push profile handler.
 * 
 * All opp related messages from TSB stack will be processed by this function
 * 
 * @param op_code TSB opp opcode
 * @param param data of parameter
 * 
 * @return process result
 */
int oppProfileHandler(UCHAR op_code, param_data* param)
{
	int ret = C2_OK;
	
	switch(op_code)
	{
		case TCU_OPP_SVR_SETUP_RESP:
		{
			eventOPPStartup(param);
			break;
		}
		case TCU_OPP_SVR_SHUTDOWN_RESP:
		{
			eventOPPShutdown(param);
			break;
		}
		case TCU_OPP_SVR_CONNECT_EVENT:
		{
			oppConnectResult(param);
			break;
		}
		case TCU_OPP_SVR_DISCONNECT_EVENT:
		{
			oppDisconnectResult(param);
			break;
		}
		case TCU_OPP_SVR_PUSH_REQUEST_EVENT:
		{
			evtOPPPushRequest(param);
			break;
		}
		case TCU_OPP_SVR_PUSH_RESPONSE_EVENT:
		{
			break;
		}
		case TCU_OPP_SVR_PUSH_ABORT_EVENT:
		{
			evtOPPPushAbort();
			break;
		}
		case TCU_OPP_SVR_FC_SETTING_RESP:
		{
			resOppFlowControl(param);
			break;
		}
		default:
		{
			break;
		}
	}
	return ret;
}

/*!
 * @brief opp host message handler.
 * 
 * All opp related messages from host will be processed by this function
 * 
 * @param op_code Alps opp opcode
 * @param param data of parameter
 * 
 * @return process result
 */
int oppHostHandler(uint16 op_code, param_data* param)
{
	int ret =C2_OK;
	
	if(op_code>= HOST_OPPS_FLOW_CTRL_REQ && op_code <= HOST_OPPS_ABORT_REQ)
	{
		setOpcode(op_code);
	}	
	switch(op_code)
	{
		case HOST_OPPS_FLOW_CTRL_REQ:
		{
			reqOppFlowControl(param);
			break;
		}
		case HOST_OPPS_ABORT_REQ:
		{
			reqOppAbort();
			break;
		}

		default:
		{
			/*! inform host it is an unknown opcode */
			genericHostMsgTwoExt(HOST_GEN_ERROR_CFM, EVTRES_UNKNOWN_OPCODE,op_code);
			break;
		}
	}/* end switch */
	return ret;
}



void oppAcceptHandler(uint8 status, uint8 op_code)
{
	switch (op_code)
	{

		case TCU_OPP_SVR_SETUP_REQ:
		{
			break;
		}	
		case TCU_OPP_SVR_SHUTDOWN_REQ:
		{
			break;
		}
		case TCU_OPP_SVR_PUSH_RESPONSE_REQ:
		{
				
			break;
		}
		case TCU_OPP_SVR_PUSH_ABORT_REQ:
		{
			cfmOppAbort(status);
			break;
		}
		case TCU_OPP_SVR_FC_SETTING_REQ:
		{
			break;
		}
		default:
		{
			break;
		}
	}

}
